<?php
class tbl_account extends AppModel
{
    public $useTable = 'tbl_account';
    public $useDbConfig = 'tales_of_deonia';
    public $primaryKey = 'a2x_id';
    public $order = array('last_login_date' => 'DESC');

    public function get_account($_id)
    {
        $params = array(
            'conditions' => array(
                'a2x_id' => $_id,
            ),
            'fields' => array(
                'a2x_id', 'nickname', 'block', 'gem', 'last_login_date', 'register_date'
            ),
        );

        $data = $this->find('first', $params);

        return $data;
    }

    public function search_nickname($_nickname)
    {
        $params = array(
            'conditions' => array(
                'or' => array(
                    "nickname LIKE" => "%$_nickname%",
                ),
            ),
            'fields' => array(
                'a2x_id', 'nickname', 'block', 'gem', 'last_login_date', 'register_date'
            ),
        );

        $data = $this->find('all', $params);

        return $data;
    }

    public function get_total_count()
    {
        $ru_count = $this->find('count');
        $params = array(
            'conditions' => array(
                'block' => 1
            ),
        );
        $block_count = $this->find('count', $params);
        $data = array(
            'ru_count' => $ru_count,
            'block_count' => $block_count
        );

        return $data;
    }

    public function get_nru($_date)
    {
        $params = array(
            'fields' => array('register_date'),
            'conditions' => array(
                'DATE(register_date)' => $_date
            ),
        );
        $data = $this->find('count', $params);

        return $data;
    }

    public function get_dau($_date)
    {
        $params = array(
            'fields' => array('last_login_date'),
            'conditions' => array(
                'DATE(last_login_date)' => $_date
            ),
        );
        $data = $this->find('count', $params);

        return $data;
    }
}